# 加油！杨思钦！
# 沉下心来慢慢琢磨，你是最棒的！
import uuid
import requests
import base64
import json


# 使用第三方接口，识别图片中的文字
def base64_api(uname, pwd, img, typeid):

    base64_data = base64.b64encode(img)
    b64 = base64_data.decode()
    data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
    result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
    if result['success']:
        return result["data"]["result"]
    else:
        return result["message"]
    return ""


if __name__ == "__main__":
    img_path = "v_demo.png"
    result = base64_api(uname='sqyang', pwd='qaz147258', img=img_path, typeid=3)
    print(result)
